import 'package:flutter/material.dart';
import 'package:whale/helper/utils/util.dart';
import 'package:whale/pages/im/component/im_input/index.dart';

import 'index.dart';
import 'widgets/widgets.dart';

class ImPage extends GetView<ImController> {
  const ImPage({Key? key}) : super(key: key);

  // 主视图
  Widget _buildView() {
    var state = controller.state;
    return GestureDetector(
      onTap: () {
        var inputCtrl = Get.find<ImInputController>();

        inputCtrl.resignFirstResponder();
      },
      child: ListView(
        controller: state.sc,
        children: state.list?.map((e) => IMCell(md: e)).toList() ?? [],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<ImController>(
      builder: (_) {
        return Scaffold(
          appBar: detailAppBar(
            context,
            title: controller.state.imListMd.fromUser.name,
          ),
          body: SafeArea(
            child: _buildView(),
          ),
          floatingActionButtonLocation:
              FloatingActionButtonLocation.centerDocked,
          floatingActionButton: MediaQuery.removePadding(
              context: context,
              removeTop: true,
              removeBottom: true,
              child: ImInputPage()),
          bottomNavigationBar: IMInputKeyboardView(),
        );
      },
    );
  }
}
